// ignore_for_file: depend_on_referenced_packages

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_ability/custom_ui.dart';

class FieldWidget extends StatefulWidget {
  const FieldWidget({Key? key}) : super(key: key);

  @override
  State<FieldWidget> createState() => _FieldWidgetState();
}

class _FieldWidgetState extends State<FieldWidget> {
  int groupValue = 0;
  int groupValue2 = 0;
  TextEditingController textEditingController = TextEditingController();
  YJCodeState yjCodeState = YJCodeState.none;
  YJCodeState yjCodeState2 = YJCodeState.none;

  @override
  void initState() {
    super.initState();
    textEditingController.text = "实际内容";
  }

  @override
  void dispose() {
    textEditingController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: TextView.text("输入框"),
      ),
      backgroundColor: YJColors.BACKGROUND_COLOR,
      body: Container(
        padding:
            const EdgeInsets.only(left: 16, right: 16, top: 10, bottom: 40),
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              buildPadding("按钮验证码"),
              YJTextField(
                titleString: "验证码",
                hintText: "请输入验证码",
                rightWidgetMode: YJTextFieldMode.code,
                inputFormatters: <TextInputFormatter>[
                  LengthLimitingTextInputFormatter(6),
                  FilteringTextInputFormatter.digitsOnly,
                ],
                rightWidget: YJCodeButton(
                  phoneNo: "13488771717",
                  isTextButton: true,
                  yjCodeState: yjCodeState,
                  speed: 30,
                  sendCodeCallBack: () async {
                    /// 接口请求
                    await Future.delayed(const Duration(milliseconds: 1000));
                    setState(() {
                      yjCodeState = YJCodeState.sendCodeSuccess;
                    });
                  },
                ),
              ),
              buildPadding("文本验证码"),
              YJTextField(
                titleString: "验证码",
                hintText: "请输入验证码",
                rightWidgetMode: YJTextFieldMode.code,
                inputFormatters: <TextInputFormatter>[
                  LengthLimitingTextInputFormatter(6),
                  FilteringTextInputFormatter.digitsOnly,
                ],
                rightWidget: YJCodeButton(
                  phoneNo: "13488771717",
                  yjCodeState: yjCodeState2,
                  speed: 30,
                  sendCodeCallBack: () async {
                    /// 接口请求
                    await Future.delayed(const Duration(milliseconds: 1000));
                    setState(() {
                      yjCodeState2 = YJCodeState.sendCodeSuccess;
                    });
                  },
                ),
              ),
              buildPadding("带标签输入框"),
              const YJTextField(
                titleString: "标题内容",
                hintText: "请输入内容",
                rightWidgetMode: YJTextFieldMode.none,
              ),
              buildPadding("必填输入"),
              YJTextField(
                titleWidget: Row(
                  children: [
                    TextView.text("*", color: Colors.red),
                    TextView.text("标题内容",
                        color: YJColors.BLACK85, fontSize: YJSize.sp(16)),
                  ],
                ),
                hintText: "请输入内容",
                rightWidgetMode: YJTextFieldMode.editing,
              ),
              buildPadding("无标题内容"),
              const YJTextField(
                hintText: "请输入内容",
                rightWidgetMode: YJTextFieldMode.editing,
              ),
              buildPadding("禁用状态"),
              YJTextField(
                controller: textEditingController,
                titleString: "标题内容",
                hintText: "请输入内容",
                readonly: true,
                rightWidgetMode: YJTextFieldMode.none,
              ),
              buildPadding("错误提示"),
              const YJTextField(
                titleString: "标题内容",
                hintText: "请输入内容",
                errorPrompt: true,
                rightWidgetMode: YJTextFieldMode.editing,
              ),
              buildPadding("标题输入框上下排布"),
              const YJTextField(
                titleString: "标题内容",
                hintText: "请输入内容",
                yjTextFieldType: YJTextFieldType.vertical,
                rightWidgetMode: YJTextFieldMode.editing,
              ),
              buildPadding("带选择的输入框"),
              YJTextField(
                titleString: "标题内容",
                hintText: "请输入内容",
                rightWidgetMode: YJTextFieldMode.never,
                enabled: false,
                onTap: () {},
              ),
            ],
          ),
        ),
      ),
    );
  }

  Padding buildPadding(String title) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 16),
      child: TextView.text(title),
    );
  }
}
